<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8"/>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
        <title>AJ Utils-StrUtil Tutorial</title>
        <meta name="description" content="Small Java utilities with many useful functions. Provides utility methods for string manipulation in Java applications" />
        <meta name="keywords" content="AJ Utils, ajaxjs, ajaxjs framework, java utilities, tools, helper, string,utilities,manipulation" />
        <meta name="viewport" content="width=device-width, initial-scale=1"/>
        <link rel="stylesheet" href="https://framework.ajaxjs.com/static/new-ui/css/common.css" />
        <link rel="stylesheet" href="https://iam.ajaxjs.com/asset/main.css"/>
        <link rel="icon" type="image/x-icon" href="https://framework.ajaxjs.com/aj-logo/logo.ico"/>
        <script src="https://framework.ajaxjs.com/static/aj-docs/common.js"></script>
        <script>
            // 获取用户的默认语言
            var userLang = navigator.language || navigator.userLanguage;

            // 检查是否为中文环境（包括简体和繁体）
            if (userLang.startsWith('zh') && location.pathname.indexOf('cn') == -1) {
                 confirm('欢迎！您可以改为访问中文内容。是否继续？') && location.assign('/cn');  // 如果是中文，则弹出提示
            }

            var _hmt = _hmt || [];
            (function() {
              var hm = document.createElement("script");
              hm.src = "https://hm.baidu.com/hm.js?208c5aea11c52991bd1c3283e62ad0ce";
              var s = document.getElementsByTagName("script")[0];
              s.parentNode.insertBefore(hm, s);
            })();
        </script>
    </head>
    <body>
        <nav>
            <div>
                <div class="links">
                    <a href="/">🏠 Home</a>
                    | ⚙️ Source:
                    <a target="_blank" href="https://github.com/lightweight-component/aj-util">Github</a>/<a target="_blank" href="https://gitcode.com/lightweight-component/aj-util">Gitcode</a>
                    | 🚀 <a href="/cn">Chinese Version</a>
                </div>
                <h1>
                    <img src="https://framework.ajaxjs.com/aj-logo/logo.png" style="vertical-align: middle;height: 45px;margin-bottom: 6px;" />
                    AJ Utils
                </h1>
                <h3>Small Java Utils Library</h3>
            </div>
        </nav>
        <div>
            <menu>
                
                <ul>
                    <li class="selected">
                        <a href="/">Home</a>
                    </li>
                </ul>
                <h3>Common</h3>
                <ul>
                    <li><a href="/common/JsonUtil/">JsonUtil</a></li>
                    <li><a href="/common/BytesHelper/">BytesHelper</a></li>
                    <li><a href="/common/ConvertBasicValue/">ConvertBasicValue</a></li>
                    <li><a href="/common/MessageDigestHelper/">HashHelper</a></li>
                    <li><a href="/common/MapTool/">MapTool</a></li>
                    <li><a href="/common/ObjectHelper/">ObjectHelper</a></li>
                    <li><a href="/common/RandomTools/">RandomTools</a></li>
                    <li><a href="/common/RegExpUtils/">RegExpUtils</a></li>
                    <li><a href="/common/StrUtil/">StrUtil</a></li>
                    <li><a href="/common/BoxLogger/">BoxLogger</a></li>
                    <li><a href="/common/BytesHelper/">BytesHelper</a></li>
                    <li><a href="/common/EncodeTools/">UrlEncode</a></li>
                    <li><a href="/common/XmlHelper/">XmlHelper</a></li>
                    <li><a href="/common/WebUtils/">WebUtils</a></li>
                </ul>
                <h3>Date Handing</h3>
                <ul>
                    <li><a href="/date/intro/">Introduction</a></li>
                    <li><a href="/date/convert/">Date Converter</a></li>
                    <li><a href="/date/formatter/">Date Formatter</a></li>
                </ul>
                <h3>Reflection</h3>
                <ul>
                    <li><a href="/reflect/Methods/">Methods</a></li>
                    <li><a href="/reflect/Types/">Types</a></li>
                    <li><a href="/reflect/Clazz/">Clazz</a></li>
                </ul>

                <h3>IO</h3>
                <ul>
                    <li><a href="/io/FileHelper/">FileHelper</a></li>
                    <li><a href="/io/Resources/">Resources</a></li>
                    <li><a href="/io/StreamHelper/">DataReader/DataWriter</a></li>
                    <li><a href="/io/ZipHelper/">ZipHelper</a></li>
                </ul>

                <h3>HTTP Request</h3>
                <ul>
                    <li><a href="/http_request/Get">HTTP Request</a></li>
                    <li><a href="/http_request/advanced-usage/">Advanced Usage</a></li>
                    <li><a href="/http_request/Base/">Base</a></li>
                </ul>
    
               <h3>Cryptography</h3>
               <ul>
                <li><a href="/cryptography/intro/">Introduction</a></li>
                <li><a href="/cryptography/flow/">Basic Flow</a></li>
                <li><a href="/cryptography/AesCrypto/">AES/DES</a></li>
                <li><a href="/cryptography/RsaCrypto/">RSA</a></li>
               </ul>
            </menu>
            <article class="aj-text">
                <h1>StrUtil Tutorial</h1>
<p>This tutorial provides an overview of the <code>StrUtil</code> class, which is part of the <code>lightweight-component/aj-util</code> library. The <code>StrUtil</code> class provides utility methods for string manipulation in Java applications.</p>
<h2>Introduction</h2>
<p>The <code>StrUtil</code> class contains static methods for common string operations including validation, concatenation, padding, templating, and encoding conversions.</p>
<h2>Main Features</h2>
<ul>
<li>String validation and empty checks</li>
<li>URL path concatenation</li>
<li>String templating with placeholders</li>
<li>String padding and formatting</li>
<li>List/array joining with custom delimiters</li>
<li>UTF-8 encoding/decoding utilities</li>
<li>Pattern matching and replacement</li>
</ul>
<h2>Constants</h2>
<ol>
<li><code>EMPTY_STRING</code> - Empty string constant</li>
<li><code>DELIM_STR</code> - Default template delimiter &quot;{}&quot;</li>
</ol>
<h2>Methods</h2>
<h3>1. Validation</h3>
<ol>
<li><code>hasText(String str)</code> - Check if string contains actual text</li>
<li><code>isEmptyText(String str)</code> - Opposite of hasText()</li>
</ol>
<h3>2. Concatenation</h3>
<ol>
<li><code>concatUrl(String a, String b)</code> - Smart URL path concatenation</li>
<li><code>join(T[] arr, String str)</code> - Join array with delimiter</li>
<li><code>join(List&lt;T&gt; list, String str)</code> - Join list with delimiter</li>
<li><code>join(List&lt;String&gt; list, String tpl, String str)</code> - Join with template formatting</li>
</ol>
<h3>3. Templating</h3>
<ol>
<li><code>print(String tpl, Object... args)</code> - Simple {} placeholder replacement</li>
<li><code>simpleTpl(String template, Map&lt;String, Object&gt; params)</code> - ${var} replacement</li>
<li><code>simpleTpl2(String template, Map&lt;String, Object&gt; data)</code> - #{var} replacement</li>
<li><code>simpleTpl(String template, Object data)</code> - JavaBean property replacement</li>
</ol>
<h3>4. Utilities</h3>
<ol>
<li><code>charCount(String str, String _char)</code> - Count character occurrences</li>
<li><code>leftPad(String str, int len, String _char)</code> - Left pad string</li>
<li><code>isWordOneOfThem(String word, String[] arr)</code> - Check string in array</li>
<li><code>getUTF8_Bytes(String str)</code> - Get UTF-8 bytes</li>
<li><code>byte2String(byte[] bytes)</code> - Convert bytes to UTF-8 string</li>
<li><code>byte2String(String str)</code> - Re-encode string as UTF-8</li>
</ol>
<h2>Usage Examples</h2>
<h3>Validation</h3>
<pre><code class="language-java">boolean valid = StrUtil.hasText(&quot;  test  &quot;); // true
boolean empty = StrUtil.isEmptyText(&quot;   &quot;); // true
</code></pre>
<h3>URL Concatenation</h3>
<pre><code class="language-java">String url = StrUtil.concatUrl(&quot;http://example.com&quot;, &quot;api&quot;); 
// &quot;http://example.com/api&quot;
</code></pre>
<h3>Templating</h3>
<pre><code class="language-java">String result = StrUtil.print(&quot;Hello {}!&quot;, &quot;World&quot;); // &quot;Hello World!&quot;
String tpl = StrUtil.simpleTpl(&quot;Name: ${name}&quot;, Map.of(&quot;name&quot;, &quot;John&quot;)); 
// &quot;Name: John&quot;
</code></pre>
<h3>Joining</h3>
<pre><code class="language-java">String joined = StrUtil.join(List.of(&quot;a&quot;,&quot;b&quot;,&quot;c&quot;), &quot;,&quot;); // &quot;a,b,c&quot;
</code></pre>
<h3>Encoding</h3>
<pre><code class="language-java">byte[] bytes = StrUtil.getUTF8_Bytes(&quot;test&quot;);
String str = StrUtil.byte2String(bytes); // &quot;test&quot;
</code></pre>
<h2>Conclusion</h2>
<p>The <code>StrUtil</code> class provides comprehensive utility methods for string manipulation, making common string operations more convenient in Java applications.</p>

            </article>
        </div>

       <footer>
            AJ-Util, a part of <a href="https://framework.ajaxjs.com" target="_blank">AJ-Framework</a> open source. Mail:
            frank@ajaxjs.com, visit <a href="https://blog.csdn.net/zhangxin09" target="_blank">my blog(In Chinese)</a>.
            <br />
            <br />
            Copyright © 2025 Frank Cheung. All rights reserved.
        </footer>
    </body>
</html>